package com.sg.web;

import com.sg.bean.Join;
import com.sg.service.JoinService;
import com.sg.vo.JoinVO;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.List;

/**
 * @author lyx
 * 招聘信息（第三方）控制器
 */
@Controller
public class JoinController {
    @Autowired
    JoinService joinService;

    Logger logger = Logger.getLogger(JoinController.class);

    @RequestMapping("/join/joinlist")
    public String joinlist(Model model) {
        logger.info("joinlist---");
        List<JoinVO> joinlist = joinService.findAll();
        logger.info("joinlist size: " + joinlist.size());
        model.addAttribute("joinlist", joinlist);
        return "join/joinlist";
    }


    @RequestMapping("/join/toaddjoin")
    public String toaddjoin() {
        logger.info("toaddjoin---");
        return "join/addjoin";
    }

    @RequestMapping("/join/addjoin")
    public String addjoin(Join join) {
        logger.info(join);
        boolean flag = joinService.add(join);
        logger.info(flag);
        return "redirect:joinlist.action";//返回到列表控制器，重定向
    }

    @RequestMapping("/join/deletejoin")
    public String deletejoin(int joinId) {
        boolean flag = joinService.delete(joinId);
        logger.info(flag);
        return "redirect:joinlist.action";
    }
    @RequestMapping("/join/toupdatejoin")
    public String toupdatejoin(int joinId, Model model) {
        logger.info("toupdatejoin---");
        Join join = joinService.findById(joinId);
        model.addAttribute("join",join);

        return "join/updatejoin";
    }
    @RequestMapping("/join/updatejoin")
    public String updatejoin(int joinId) {
        boolean flag = joinService.update(joinId);
        logger.info(flag);
        return "redirect:joinlist.action";
    }

    //普通用户招聘页面控制器地址
    @RequestMapping("/user/joinlist")
    public String joinuserlist(Model model) {
        logger.info("joinlist---");
        List<JoinVO> joinlist = joinService.findAll();
        logger.info("joinlist size: " + joinlist.size());
        model.addAttribute("joinlist", joinlist);
        return "user/joinlist";
    }
}
